package com.csii.ssm.listener;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

public class SystemSessionContext {

    /**
     * ctx:存储应用当前使用中的httpsession集合 key sessionid
     *
     * @since 1.0.0
     */
    private static final Map<String, HttpSession> ctx = new HashMap<String, HttpSession>();

    private SystemSessionContext() {
    }

    /**
     * addSessoin 添加session
     *
     * @param session void
     * @throws
     * @since 1.0.0
     */
    public static void addSessoin(HttpSession session) {

        ctx.put(session.getId(), session);
    }

    /**
     * removeSession 移除session
     *
     * @param session void
     * @throws
     * @since 1.0.0
     */
    public static void removeSession(HttpSession session) {
        ctx.remove(session.getId());
    }

    /**
     * getSession 通过sessionid获取对应的session
     *
     * @param sessionId
     * @return HttpSession
     * @throws
     * @since 1.0.0
     */
    public static HttpSession getSession(String sessionId) {
        return ctx.get(sessionId);
    }
}
